package com.pan.config;

import com.pan.interceptor.CartInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration registration = null;
        registry.addInterceptor(handlerCartInterceptorNotAutoWiredQuestion()).addPathPatterns("/cart/**");
    }

//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        InterceptorRegistration registration = null;
//        //super.addInterceptors(registry);
//        //静态资源 css/js/image     springboot已经做好静态资源映射了，无需进行处理
//        //方式一：拦截器中没有依赖注入时使用该方式
//        //registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**").excludePathPatterns("/", "/index.html", "/user/login", "/user/logout");
//
//        //方式二：拦截器中没有依赖注入时使用该方式
//        registry.addInterceptor(handlerLoginHandlerInterceptorNotAutoWiredQuestion()).addPathPatterns("/**").excludePathPatterns("/", "/index.html", "/user/login", "/user/logout");
//    }

    @Bean
    public CartInterceptor handlerCartInterceptorNotAutoWiredQuestion() {
        return new CartInterceptor();
    }

}
